﻿using System;
using System.Collections.Generic;
using System.IO;
using Furion;
using Furion.TaskScheduler;
using Furion.UnifyResult;
using Furion.Logging;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;

Serve.Run("http://0.0.0.0:8085");

public class Startup : AppStartup
{

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvcFilter<LoggingMonitorAttribute>();
        services.AddMonitorLogging();
        services.AddLogging(builder =>
            {
                // 错误级别日志归类
                builder.AddFile("logs/{0:yyyyMMdd}-error.log",
                    options =>
                    {
                        options.WriteFilter = (logMsg) => { return logMsg.LogLevel == LogLevel.Error; };
                        options.FileNameRule = filename => { return string.Format(filename, DateTime.Now); };
                    });
                // 每天创建一个日志文件
                builder.AddFile("logs/{0:yyyyMMdd}--LogInfo.log",
                    options =>
                    {
                        options.WriteFilter = (logMsg) => { return logMsg.LogLevel == LogLevel.Information; };
                        options.FileNameRule = fileName => { return string.Format(fileName, DateTime.Now); };
                    });
            });
    }
}

[DynamicApiController]
public class HelloService
{
    public string Say()
    {
        return "Hello, Furion";
    }

     public string Sayone()
    {
         SpareTime.DoIt(() =>{
            Log.Information("Information333333");
         });

        return "Hello, Furion";
    }
}